package com.gx.admin.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gx.admin.service.CourseService;
import com.student.demo.entity.Course;
import com.student.demo.entity.Teacher;
import com.student.demo.repository.CourseRepository;

@Controller
@RequestMapping("course")
public class CourseController {
	
	@Resource
	private CourseService courseService;
	@Autowired
	private CourseRepository courseRepository;
	@GetMapping("add")
	public String add() {
		return "addcar";
	}
	//添加
	@PostMapping("addcars")
	@ResponseBody
	public Object add(@Valid Course course) {
		Course course2 = courseService.add(course);
		return course;
	}
	//查询
	@RequestMapping("all")
	@ResponseBody
	public Object findAll(Integer page,Map<String, Object>map) {
		List<Course> courses = courseService.findByPage(page, 10);
		map.put("courses",courses);
		return courseService.findByPage(page, 10);
//		return teachers;
	}

	//删除
	@RequestMapping("del")
	@ResponseBody
	public Object del(Integer id) {
		courseService.remove(id);
		 return "删除成功";
	}
	
//	@RequestMapping("by_number")
//	@ResponseBody
//	public Teacher findBnuber(String bname) {
//	return	teacherService.findBnumber(bname);
//	}
	
	@RequestMapping("/findByNameLike")
	@ResponseBody
    public List<Course> findBydName(String name) {
        // 一定要加 "%"+参数名+"%"
        return courseService.findBydName(name);
    }

}
